/**
 * 
 */
package niuke;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author zhongfang
 *
 */
public class 游历魔法王国 {

	static class Node {
		int index;
		ArrayList<Node> childs = new ArrayList<>();
		Node parent;
	}

	static int maxCount = 0;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int L = scanner.nextInt();
		Node[] nodes = new Node[n];
		nodes[0] = new Node();
		for (int i = 0; i < n - 1; i++) {
			nodes[i + 1] = new Node();
			nodes[i + 1].index = i + 1;
			int parent = scanner.nextInt();
			// nodes[i + 1].childs.add(nodes[parent]);
			nodes[i + 1].parent = nodes[parent];
			nodes[parent].childs.add(nodes[i + 1]);
		}
		boolean visited[] = new boolean[n];
		visited[0] = true;
		dfs(nodes[0], L, visited, 1);
		System.out.println(maxCount);
	}

	private static void dfs(Node node, int remainStep, boolean[] visited, int visitedCount) {
		if (remainStep == 0) {
			maxCount = Math.max(maxCount, visitedCount);
			return;
		}
		for (Node neibor : node.childs) {
			visited[neibor.index] = true;
			dfs(neibor, remainStep - 1, visited, visitedCount + 1);
			visited[neibor.index] = false;
		}
		if (node.parent != null) {
			dfs(node.parent, remainStep - 1, visited, visitedCount);
		}
	}
}
